package PVZ;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;

//植物父类
public class P {
    public  int Cost;//需要的阳光费用
    public  int Blood;//血量
      /* //消耗阳光
        Game.s=Game.s-this.Cost;
        Game.sun=""+Game.sun+"";*/
    //植物的功能
    public void Skill(){
    }
}
//向日葵
class SunFlower extends P{
    public  int Cost=50;
    public  int Blood=10;
    public  void Skill(int x,int y) {
       ///产生阳光
        SUN s=new SUN(x,y);
        Thread thread1=new Thread(s);
            thread1.start();
    }
}
class SUN implements Runnable {
    public  int x, y;
    public SUN(int x, int y) {
        this.x = x;
        this.y = y;
    }
    Object lock=new Object();
    public void run() {
            while (Game.ifGame) {
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Game g=new Game();
                g.importSun(x, y);
                Game.p1.repaint();
            }
    }
}
//豌豆射手
class Peashooter extends P {
    public int Cost = 100;
    public int Blood = 10;
    public void Skill(int x,int y) {
        //如果此行有僵尸，则发射豌豆
        Pea p=new Pea(x+40,y,1);
        Thread thread1=new Thread(p);
        thread1.start();
    }
}
class Pea implements Runnable{
    public int x, y;
    public int type;
    public Pea(int x, int y,int type) {
        this.x = x;
        this.y = y;
        this.type=type;
    }
    public void run(){
        while (Game.ifGame) {
            try {
                try {
                    Game.Pictrue1.Pea= ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Plants\\dou.gif"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                int x1=x;
                int y1=y;
                Thread.sleep(1500);
                for(;x1<(1920-Game.X_OFFSET);){
                    Game.ifPeas[x1][y1]=1;
                    if(type==2){
                        Game.ifPeas[x1-40][y1]=1;
                    }
                    Game.p1.DrawPea(x1,y1,type);
                    //Game.p1.repaint();
                    Thread.sleep(10);x1=x1+10;
                    Game.ifPeas[x1][y1]=0;
                    if(type==2){
                        Game.ifPeas[x1-40][y1]=0;
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
                //Game.p1.DrawPea(x, y,1);
        }
    }
}
//坚果墙
class WallNut extends P {
    public int Cost = 50;
    public int Blood = 100;
    public void Skill() {

    }
}
//双重射手
class RePeater extends P {
    public int Cost = 200;
    public int Blood = 10;
    public void Skill(int x,int y) {
        Pea p=new Pea(x+40,y,2);
        Thread thread1=new Thread(p);
        thread1.start();
    }
}
//樱桃炸弹
class CherryBomb extends P {
    public int Cost = 150;
    public int Blood = 10;
    public void Skill() {
    }
}
//土豆地雷
class PotatoMine extends P {
    public int Cost = 25;
    public int Blood = 10;
    public void Skill() {
    }
}